﻿Imports QLTHUVIEN.DTO
Imports QLTHUVIEN.BUS

Public Class frmTheLoaiSach

    Private Sub layDanhSach()
        Dim TheLoaiSachBus As TheLoaiSachBUS = New TheLoaiSachBUS()
        Dim data As DataTable = TheLoaiSachBUS.layDanhSach()
        dtgDanhSachTheLoaiSach.DataSource = data
    End Sub

    Private Sub frmTheLoaiSach_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        layDanhSach()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If txtTenTheLoai.Text = "" Then
            Return
        End If

        Dim TheLoaiSachDto As New TheLoaiSachDTO()
        TheLoaiSachDto.TenTheLoaiSach = txtTenTheLoai.Text

        Dim tlSachBus As New TheLoaiSachBUS()
        tlSachBus.ThemTheLoaiSach(TheLoaiSachDto)

        layDanhSach()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        If txtTenTheLoai.Text = "" Or txtMaTheLoai.Text = "" Then
            Return
        End If

        Dim TheLoaiSachDto As New TheLoaiSachDTO()
        TheLoaiSachDto.MaTheLoaiSach = txtMaTheLoai.Text
        TheLoaiSachDto.TenTheLoaiSach = txtTenTheLoai.Text
        TheLoaiSachDto.IsDelete = False

        Dim bcBus As New TheLoaiSachBUS()
        bcBus.SuaTheLoaiSach(TheLoaiSachDto)

        layDanhSach()
    End Sub

    Private Sub dtgDanhSachTheLoaiSach_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgDanhSachTheLoaiSach.CellClick
        txtMaTheLoai.Text = dtgDanhSachTheLoaiSach.CurrentRow.Cells(0).Value.ToString()
        txtTenTheLoai.Text = dtgDanhSachTheLoaiSach.CurrentRow.Cells(1).Value.ToString()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim TheLoaiSachDto As New TheLoaiSachDTO()
        TheLoaiSachDto.MaTheLoaiSach = txtMaTheLoai.Text
        TheLoaiSachDto.TenTheLoaiSach = txtTenTheLoai.Text
        TheLoaiSachDto.IsDelete = True

        Dim tlSachBus As New TheLoaiSachBUS()
        tlSachBus.xoaTheLoaiSach(TheLoaiSachDto)

        layDanhSach()
    End Sub

End Class